using System;
using System.Linq;
using System.Collections.Generic;

using DemoApp.DataAccess;

using EntModApp.EntServices.Business;
using EntModApp.EntServices.Data;

namespace DemoApp.BusinessLayer 
{
  public partial class PersonObjectRepository : 
    IPersonObjectRepository 
  {
    public IBusinessObjectCollection<IPerson> RetrieveAll()
    {
      var query = new PersonLoadSettings();
      return Retrieve(query);
    }

    public IBusinessObjectCollection<IPerson> Retrieve(PersonLoadSettings query)
    {
      query = PersonLoadSettings.FromPersonLoadSettings(query);
      if (query.AsReadonly)
      {
        var result = CslaPersonInfoCollection.GetPersonInfoCollection(query);
        return result;
      }
      else
      {
        var result = CslaPersonEditCollection.GetPersonEditCollection(query);
        return result;
      }
    }

    public IPerson RetrieveOne(PersonLoadSettings query)
    {
      query = PersonLoadSettings.FromPersonLoadSettings(query);
      if (query.AsReadonly)
      {
        var result = CslaPersonInfoCollection.GetPersonInfoCollection(query);
        return result.FirstOrDefault<IPerson>();
      }
      else
      {
        var result = CslaPersonEditCollection.GetPersonEditCollection(query);
        return result.FirstOrDefault<IPerson>();
      }
    }

    public int Count()
    {
      return Count(null);
    }

    public int Count(PersonLoadSettings query)
    {
      query = PersonLoadSettings.FromPersonLoadSettings(query);
      return CslaPersonInfoCollection.GetCount(query);
    }

    public IPerson New()
    {
      return CslaPersonEdit.New();
    }

    public void Save(IBusinessObjectCollection<IPerson> collection)
    {
      throw new NotImplementedException();
    }

    public void Save(IPerson obj)
    {
      throw new NotImplementedException();
    }
  }
}
